/*
 * Copyright (C) 2011, EADS France
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */

package xowl.interpreter.backends.rdf;

/**
 *
 * @author Laurent WOUTERS
 */
public class RDFTriple {
    private RDFSubjectNode subject;
    private RDFProperty property;
    private RDFNode object;

    public RDFSubjectNode getSubject() { return subject; }
    public RDFProperty getProperty() { return property; }
    public RDFNode getObject() { return object; }
    public RDFNode getField(RDFTripleField field) {
        switch (field) {
            case Subject: return subject;
            case Property: return property;
            case Value: return object;
        }
        return null;
    }

    public RDFTriple(RDFSubjectNode subject, RDFProperty property, RDFNode object) {
        this.subject = subject;
        this.property = property;
        this.object = object;
    }

    @Override public int hashCode() {
        int hash = 5;
        hash = 53 * hash + (this.subject != null ? this.subject.hashCode() : 0);
        hash = 53 * hash + (this.property != null ? this.property.hashCode() : 0);
        hash = 53 * hash + (this.object != null ? this.object.hashCode() : 0);
        return hash;
    }
    @Override public boolean equals(Object obj) {
        if (obj instanceof RDFTriple)  {
            RDFTriple triple = (RDFTriple)obj;
            if (!subject.equals(triple.subject)) return false;
            if (!property.equals(triple.property)) return false;
            return (object.equals(triple.object));
        }
        return false;
    }
    @Override public String toString() {
        java.lang.StringBuilder builder = new java.lang.StringBuilder("[");
        builder.append(subject.toString());
        builder.append(" ");
        builder.append(property.toString());
        builder.append(" ");
        builder.append(object.toString());
        builder.append("]");
        return builder.toString();
    }
}
